package com.lesama.properties;

/*
    Properties 和 IO 相关的方法
        void load(InputStream inStream) 从流中加载数据到集合（字节流）
        void load(Reader reader) 从流中加载数据到集合（字符流）
        void store(OutputStream out, String comment) 将集合的键值对写出到文件（字节流）
        void store(Writer writer, String comment) 将集合的键值对写出到文件（字符流）
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class PropertiesDemo1 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        FileInputStream fis = new FileInputStream("day14\\config.properties");
        properties.load(fis);
        properties.forEach((key, value) -> System.out.println(key + "=" + value));
        fis.close();
    }

    private static void storeWriter() throws IOException {
        Properties properties = new Properties();
        properties.setProperty("lesama", "23");
        properties.setProperty("shiro", "16");
        properties.store(new FileWriter("day14\\config.properties"), null);
    }

    private static void storeOutputStream() throws IOException {
        Properties properties = new Properties();
        properties.setProperty("lesama", "23");
        properties.setProperty("shiro", "16");
        properties.store(new FileOutputStream("day14\\config.properties"), null);
    }
}
